package thinking.generics;

class Holder<T> {
    private T obj;
    public void set(T obj) {this.obj = obj;}
    public T get() {return obj;}

}
public class Wildcards {
    static void rawArgs(Holder holder, Object arg) {
        holder.set(holder);
        Object obj = holder.get();
    }
    static void unboundedArg(Holder<?> holder, Object arg) {
        // 无法add任何东西
        Object obj = holder.get();
    }
    static <T> T exact1(Holder<T> holder) {
        T t = holder.get();
        return t;
    }
    static <T> T exact2(Holder<T> holder, T arg) {
        holder.set(arg);
        return  holder.get();
    }
    static <T> T wildSubtype(Holder<? extends T> holder, T arg) {
        // error: holder.set(arg);
        return holder.get();
    }
    static <T> void wildSupertype(Holder<? super T> holder, T arg) {
        holder.set(arg);
        //error: T t = holder.get();
        Object obj = holder.get();
    }
    public static void main(String[] args) {
        Holder raw = new Holder<Long>();
        Holder<Long> qualified = new Holder<>();
        Holder<?> unbounded = new Holder<Long>();
        Holder<? extends Long> bounded = new Holder<Long>();
        Long lng = 1L;
        rawArgs(raw, lng);
        rawArgs(qualified, lng);
        rawArgs(unbounded, lng);
        rawArgs(bounded, lng);
    }
}
